import * as vscode from 'vscode';

const keys = [
    'Int8', 'Int16', 'Int32', 'Int64', 'UInt8', 'UInt16', 'UInt32', 'UInt64',
    'Float16', 'Float32', 'Float64', 'Tunple',
    'Bool', 'Rune', 'String', 'Array', 'VArray', 'Range', 'Unit'
];

export class variableCompletionItem {
    private static arr: vscode.CompletionItem[] = [];
    static create(mark: string) {
        this.arr = [];
        let tag = mark.toLowerCase().split(':')?.[1] ?? '';
        if (tag || tag === '') {
            tag = mark.toLowerCase().split('>')?.[1] ?? '';
        }
        const arr = tag === '' ? keys : keys.filter((i) => i.toLowerCase().startsWith(tag));
        this.newItems(arr);
        return this.arr;
    }

    private static newItems(marks: string[]) {
        for (const mark of marks) {
            if (mark.toLowerCase() === 'tunple') {
                const snippet = new vscode.CompletionItem('Tunple', vscode.CompletionItemKind.Snippet);
                snippet.insertText = '(T,T2)';
                this.arr.push(snippet);
            } else {
                const item = {
                    label: mark,
                    insertText: mark,
                    kind: vscode.CompletionItemKind.Variable
                };
                this.arr.push(item);
            }
        }
    }
}